<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<div id="filter" >
    <s:form cssClass="tableFilter">
        <tr>
            <th colspan="4" class="tableTitle">
                <h5>Search</h5>
            </th>
        </tr>

        <tr>
            <td>
                <label>Country:</label>
            </td>
            <td>
                <s:select name="importacion.compromisopais.id" id="country"
                          headerKey="-1" headerValue="Choose Country"
                          list="paisList"
                          listKey="id"
                          listValue="country"
                          theme="simple"
                        >
                </s:select>
            </td>
        </tr>
        <tr>
            <td>
                <label>Import Permit:</label>
            </td>
            <td>
                <s:textfield name="importacion.importPermit" theme="simple"/>
            </td>
        </tr>

        <tr>
            <td>
                <label>Drug:</label>
            </td>
            <td>
                <s:select name="droga.id" id="droga"
                          headerKey="-1" headerValue="Choose Drug"
                          list="drogaList"
                          listKey="id"
                          listValue="drugName"
                          theme="simple"
                        >
                </s:select>
            </td>
        </tr>
        <tr>
            <td>
                <label>Protocol:</label>
            </td>
            <td>
                <s:select name="protocolo.id"
                          headerKey="" headerValue="Choose Protocol"
                          list="protocolSearchList"
                          listKey="id"
                          listValue="id"
                          theme="simple"
                        />
            </td>
        </tr>

        <tr>
            <td colspan="4" class="centeredButtons">
                <s:submit value="Search" action="list" theme="simple"/>
                <s:submit value="New" action="create" theme="simple" onclick="resetForms();"/>
            </td>
        </tr>

    </s:form>
</div>

<s:if test="!list.isEmpty()">
    <div id="table_content">
        <table>
            <thead>
            <tr>
                <th>Country</th>
                <th>Import Permit</th>
                <th>Drug</th>
                <th>Initial Qty</th>
                <th>Current Balance</th>
                <th>Unit</th>
                <th>Protocols</th>
                <th>Edit</th>
                <th>Discount</th>
                <th>Balance Detail</th>
            </tr>
            </thead>
            <tbody>
           <s:iterator value="list" var="import">
            <s:iterator value="#import.drogaImportaciones" var="drogaImp">
            <tr>
                <th><s:property value="%{#import.compromisopais.country}"/></th>
                <th><s:property value="%{#import.importPermit}"/></th>
                <th><s:property value="%{#drogaImp.droga.drugName}"/></th>
                <th><s:property value="%{#drogaImp.initialQty}"/></th>
                <th><s:property value="%{#drogaImp.currentBalance}"/></th>
                <th><s:property value="%{#drogaImp.unit}"/></th>
                <th>
                    <s:iterator value="#import.protocoloImportaciones" var="protImp" status="st">
                        <s:if test="%{#protImp.fecha == null}">
                            <s:property value="%{#protImp.protocolo.id}"/><s:if test="#st.last == false">,</s:if>
                        </s:if>
                    </s:iterator>
                </th>
                <th>
                    <s:form action="create" method="POST">
                        <s:hidden value="%{#import.id}" name="editableImportationId"/>
                        <a onclick="$(this).closest('form').submit()"><img src="<s:url value="/images/edit.png"/>" title="Edit" alt="Edit"></a></TH>
                    </s:form>
                </th>
                <th>
                    <s:form action="discount" method="POST">
                    <s:hidden value="%{#drogaImp.id}" name="drogaImpToDiscountId"/>
                    <a onclick="$(this).closest('form').submit()"><img src="<s:url value="/images/discount.png"/>" title="Discount" alt="Discount"></a></TH>
                </s:form>
                </th>
                <th>
                    <s:form action="detail" method="POST">
                    <s:hidden value="%{#drogaImp.id}" name="drogaImpToDiscountId"/>
                    <a onclick="$(this).closest('form').submit()"><img src="<s:url value="/images/eye.png"/>" title="Detail" alt="Detail"></a></TH>
                </s:form>
                </th>
            </tr>
           </s:iterator>
            </s:iterator>
            <tbody>
        </table>
    </div>
</s:if>

<script type="text/javascript">
    var list = true;
</script>
<script type="text/javascript">
    $('#search').css({"color":"#EE5102","fontWeight":"bold"});
</script>